import path from 'path';

export default function setSwagger(app) {
  const swaggerConfig = {
    swaggerDefinition: {
      swagger: '2.0',
      info: {
        title: '<%= name %>',
        description: '<%= description %>',
        version: '1.0.0',
      },
      host: 'localhost:3000',
      basePath: '/public/v1',
      produces: ['application/json', 'application/xml'],
      schemes: ['http', 'https'],
      securityDefinitions: {
        JWT: {
          type: 'apiKey',
          in: 'header',
          name: 'Authorization',
          description: '接口鉴权',
        },
      },
    },
    basedir: __dirname,
    files: [path.join(__dirname, '../router/swagger.js')],
  };
  const expressSwagger = require('express-swagger-generator')(app);
  expressSwagger(swaggerConfig);
}
